//
//  HLBaseTableViewController.swift
//  HLwWeibo
//
//  Created by hqhxu on 16/2/27.
//  Copyright © 2016年 hqhxu. All rights reserved.


import UIKit

class HLBaseTableViewController: UITableViewController {

    ///实现用户没有登录显示登录界面 判断用户是否已经登录
    
    var userIsLogin:Bool = HLAccountViewModel.shareInstance.userLogin
    
    override func loadView() {
            // 测试
//        userIsLogin = true 
        //CZVistorView
        userIsLogin ? super.loadView() : setViestorView()
    }
    
    // MARK: - 设置view
    func setViestorView(){
        self.view = vistorView
        vistorView.vistorDelegate = self
        
        // 判断当前是哪一个类
        if self is HLHomeController {
            //执行动画
            vistorView.animationWithIconView()
            
        } else if self is HLMessageController {
            //掩藏homeView
            vistorView.homeView.hidden = true
            setUpVistorView("visitordiscover_image_message", meesssage: "登录后，别人评论你的微博，发给你的消息，都会在这里收到通知")
        } else if self is HLDiscoverController {
            //掩藏homeView
            vistorView.homeView.hidden = true
            setUpVistorView("visitordiscover_image_message", meesssage: "登录后，最新、最热微博尽在掌握，不再会与实事潮流擦肩而过")
        } else if self is HLProfileController {
            //掩藏homeView
            vistorView.homeView.hidden = true
            setUpVistorView("visitordiscover_image_profile", meesssage: "登录后，你的微博、相册、个人资料会显示在这里，展示给别人")
        }
        //在这里执行添加导航栏上的按钮
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: "didClickLeftItem")
        
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: UIBarButtonItemStyle.Plain, target: self, action: "didClickRightItem")
    }
    
    

    
    // MARK: - 设置vistorView的相应属性
    func setUpVistorView(iconView:String,meesssage:String){
        
        vistorView.iconView.image = UIImage(named: iconView)
        vistorView.messageLable.text = meesssage
        
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
    }
    
    //MARK: - NagetionItem上点击按钮事件
    func didClickLeftItem() {
        print("点击了注册")
        let navVC = UINavigationController(rootViewController: HLOuathViewController())
        //model出控制器
        presentViewController(navVC, animated: true, completion: nil)
    }

    func didClickRightItem() {
        
        let navVC = UINavigationController(rootViewController: HLOuathViewController())
        //model出控制器
        presentViewController(navVC, animated: true, completion: nil
        )

        
    }
    
    lazy var vistorView:HLVistorView = HLVistorView()
}


// MARK: - HLVistorViewDelegate代理方法
extension HLBaseTableViewController : HLVistorViewDelegate {
    
    func vistorDidClickLoginButton() {
        
        let navVC = UINavigationController(rootViewController: HLOuathViewController())
        //model出控制器
        presentViewController(navVC, animated: true, completion: nil
        )
    }
    
    func vistorDidClickRegistButton() {
        
        let navVC = UINavigationController(rootViewController: HLOuathViewController())
        //model出控制器
        presentViewController(navVC, animated: true, completion: nil
        )

        print("注册微博")
    }
}


